//
//  xmlReader.m
//  yuanhuaPlane
//
//  Created by zhuyuanbin on 6/22/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "xmlReader.h"


@implementation xmlReader
-(void)analyMainXml
{
	///analymainxml
	NSString *xmlStr = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"main" ofType:@"xml"] encoding:NSUTF8StringEncoding error:nil];
    NSError *error = nil;
	DDXMLDocument *xmlDoc = [[DDXMLDocument alloc] initWithXMLString:xmlStr options:DDXMLDocumentXMLKind error:&error];
	DDXMLElement *rootElement = (DDXMLElement*)[[[xmlDoc rootElement] nextNode] nextNode];
	
	for(DDXMLElement *child = rootElement;child;child = (DDXMLElement*)[child nextNode])
	{
		

		DDXMLNode *productNum         = [child attributeForName:@"productNum"];
		DDXMLNode *Description        = [child attributeForName:@"Description"];
		DDXMLNode *configureDictionary = [child attributeForName:@"configureDictionary"];
		
		
		
		
		DDXMLNode *discount          = [child attributeForName:@"discount"];
		DDXMLNode *discountprice     = [child attributeForName:@"discountprice"];
		DDXMLNode *imageUrl			 = [child attributeForName:@"imageUrl"];
		DDXMLNode *imageSize		 = [child attributeForName:@"imageSize"];
		
		DDXMLNode *saler			 = [child attributeForName:@"saler"];
		DDXMLNode *tele				 = [child attributeForName:@"tele"];
		Item *item = [[Item alloc] init];
		item.productNum	= [productNum stringValue];
		item.Description	= [Description stringValue];
		item.Discount   = [discount stringValue];
		item.DiscountPrice	= [discountprice stringValue];
		item.imageUrl		= [imageUrl stringValue];
		item.saler			= [saler stringValue];
		item.telephone		= [tele stringValue];
		
		NSString *configureString = [configureDictionary stringValue];
		NSArray *allconfigure = [configureString componentsSeparatedByString:@","];
		for (int i = 0; i < [allconfigure count]; i++)
		{
			NSString *keypairstring = [allconfigure objectAtIndex:i];
			NSArray *keyPairarray = [keypairstring componentsSeparatedByString:@":"];
			[item.configureDictionary setObject:[keyPairarray objectAtIndex:1] forKey:[keyPairarray objectAtIndex:0]];
		}
		
		NSArray *sizeArray	= [[imageSize stringValue] componentsSeparatedByString:@":"];
		CGFloat width  = [[sizeArray objectAtIndex:0] floatValue];
		CGFloat height = [[sizeArray objectAtIndex:1] floatValue];
		item.imageSize = CGSizeMake(width, height);
		
		[[menuItems getMenuItems].ItemsArray addObject:item];
		
		[item release];
	}
	
}
@end
